<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-cascades"></i>
                    {{pageTitle}}
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>

        <div class="container" :style="{'min-height': containerHeight + 'px'}">
            <div class="table-form-box">
                <h3 class="h3">离职申请单</h3>
                <table border="0" width="100%" cellpadding="0" cellspacing="1">
                    <tbody>
                        <tr class="tr-title">
                            <td colspan="6">基本信息</td>
                        </tr>
                        <tr>
                            <td align="right">离职编号</td>
                            <td>
                                <el-input
                                    placeholder="请输入内容"
                                    v-model="ruleForm.id"
                                    size="small"
                                    readonly
                                ></el-input>
                            </td>
                            <td align="right">姓名:</td>
                            <td>
                                <el-input
                                    placeholder="请输入"
                                    v-model="ruleForm.resignationUserName"
                                    size="small"
                                    readonly
                                ></el-input>
                            </td>

                            <td align="right">申请时间:</td>
                            <td>
                                <el-date-picker
                                    style="width:99%"
                                    v-model="ruleForm.applyTime"
                                    align="right"
                                    type="date"
                                    placeholder="选择日期"
                                    readonly
                                ></el-date-picker>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">所在部门</td>
                            <td>
                                <el-input v-model="ruleForm.departName" size="small" readonly></el-input>
                            </td>
                            <td align="right">所属岗位</td>
                            <td>
                                <el-input v-model="ruleForm.jobRole" size="small" readonly></el-input>
                            </td>
                            <td align="right">离职时间:</td>
                            <td>
                                <el-date-picker
                                    style="width:99%"
                                    v-model="ruleForm.resignationTime"
                                    align="right"
                                    type="date"
                                    placeholder="选择日期"
                                    readonly
                                ></el-date-picker>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">离职原因:</td>
                            <td>
                                <el-input
                                    v-model="ruleForm.resignationReason"
                                    size="small"
                                    readonly
                                ></el-input>
                            </td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                        </tr>
                        <tr>
                            <td align="right">备注:</td>
                            <td colspan="6">
                                <el-input v-model="ruleForm.remarks" type="textarea" readonly></el-input>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <!-- 上传附件 -->
            <upload-files :files="fileList" :isShowDel="false" v-if="flag"></upload-files>
        </div>
    </div>
</template>


<script>
import appMain from '../../../utils/app_main';
export default {
    data() {
        return {
            pageTitle: '',
            containerHeight: '',
            ruleForm: {
                applyTime: '', //离职申请时间
                departName: '', //部门名称 离职人信息回显
                departNo: '', //部门id  离职人信息回显
                jobRole: '', //所属岗位    离职人信息回显
                jobRoleId: '', //所属岗位ID   离职人信息回显
                remarks: '', //备注信息
                resignationReason: '', //离职原因
                resignationTime: '', //离职日期
                resignationUserId: '', //离职人id    接口查询
                resignationUserName: '' //离职人     接口查询
            },
            fileList: [],
            flag: false
        };
    },
    methods: {
        resignationFindById(id) {
            appMain
                .resignationFindById({}, id)
                .then(res => {
                    if (res.data.code === 20000) {
                        this.ruleForm = res.data.data;
                    } else {
                        this.$message.error('服务器繁忙，请稍后再试');
                    }
                })
                .catch(err => {
                    console.log(err);
                });
        },
        //根据id查询附件
        uploadFileInfoFindById(id) {
            appMain
                .uploadFileInfoFindById({}, id)
                .then(res => {
                    if (res.data.code === 20000) {
                        this.fileList = res.data.data;
                    } else {
                        this.$message.error(res.data.message);
                    }
                    this.flag = true;
                })
                .catch(err => {
                    console.log(err);
                });
        }
    },
    mounted() {
        var div_height = window.screen.availHeight;
        var height = div_height - 100;
        this.containerHeight = height - 160;
        this.pageTitle = this.$router.currentRoute.meta.title;
    },
    created() {
        //如果有id过来就是修改的
        if (this.$route.query.id) {
            let id = this.$route.query.id;
            //通过id查询对应离职信息
            this.resignationFindById(id);
            //通过id查询附件信息
            this.uploadFileInfoFindById(id);
        } else {
            //新增操作
            this.flag = true;
        }
    }
};
</script>


<style  scoped>
.container {
    padding-bottom: 50px;
}

.table-form-box table {
    background-color: #666;
}
.table-form-box .h3 {
    font-size: 22px;
    text-align: center;
    font-weight: normal;
    padding: 20px 0;
}
.table-form-box table .tr-title td {
    font-size: 14px;
    line-height: 40px;
}
.table-form-box table td,
.table-form-box table th {
    background-color: #fff;
    padding: 4px;
    min-height: 40px;
    font-size: 12px;
}
.color-ff2200 {
    color: #ff2200;
}
</style>